﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTO;
using BLL;

public partial class admin : Pagina
{
    float total = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Usuario != Permissao.Admin)
            Response.Redirect("login.aspx");

        List<Equipamento> todos = Busca.SelecionarTodos();

        Dictionary<TipoEquipamento, float> count = new Dictionary<TipoEquipamento, float>();

        foreach (Equipamento eq in todos)
        {
            if (count.ContainsKey(eq.Tipo))
                count[eq.Tipo]++;
            else
            {
                count.Add(eq.Tipo, 1);
            }
        }

        total = todos.Count;
        lblTotalEquips.Text = todos.Count.ToString();
        gridStats.DataSource = count;
        gridStats.DataBind();
    }
    protected void gridStats_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            KeyValuePair<TipoEquipamento, float> value = (KeyValuePair<TipoEquipamento, float>)e.Row.DataItem;
            (e.Row.FindControl("lblEquipTipo") as Label).Text = value.Key.ToString();
            (e.Row.FindControl("lblEquipCount") as Label).Text = value.Value.ToString();
            (e.Row.FindControl("lblEquipPc") as Label).Text = ((int)((value.Value / total) * 100)) + "%";
        }
    }
}